<template>
  <div class="public-page">
    <div>
      <Forms
        v-if="pageSetting.search"
        ref="subForm"
        :auto-query="tables.autoQuery"
        :data-from="formData"
        :list="pageSetting.search"
        :name="name"
        :sub-loading="tableLoading"
      >
        <el-form-item>
          <el-button v-if="name == 'APILog'" @click="resetApl">{{ translateTitle('Dams.ApplicationInterface.重置') }}</el-button>
        </el-form-item>
      </Forms>
      <div style="display: flex">
        <template v-if="!btnFix">
          <div v-for="(item, index) in tableTopList" :key="index">
            <vui-upload
              v-if="item.FUNCTION_URI == 'import'"
              ref="fileUploadRef"
              :auto-upload="true"
              :file-name="tables.uploadOptions.name"
              :limit="1"
              :post-data="tables.uploadOptions.postData"
              :show-file-list="false"
              :url="tables.uploadOptions.url"
              @uploadSuccess="uploadSuccess"
            >
              <el-button>{{ translateTitle('Dams.ApplicationInterface.导入') }}</el-button>
            </vui-upload>
            <el-button v-else-if="tables.isNew && item.FUNCTION_URI == 'newAdd' && name !== 'UserRole'" @click="common_event(item.FUNCTION_URI)">
              {{ item.BUTTON_NAME }}
            </el-button>
            <el-button v-else-if="name !== 'UserRole'" @click="common_event(item.FUNCTION_URI)">{{ item.BUTTON_NAME }}</el-button>
          </div>
        </template>
        <el-button v-else-if="noAdd.indexOf(name) == -1" @click="newAdd">{{ translateTitle('Dams.ApplicationInterface.新增') }}</el-button>
        <el-button v-if="name == 'TraceLog'" @click="appendixDownload">{{ translateTitle('Dams.ApplicationInterface.下载附件') }}</el-button>
        <el-button v-if="toCopy.indexOf(name) > -1" @click="roleCopy">{{ translateTitle('Dams.ApplicationInterface.复制') }}</el-button>
        <!-- <el-button v-if="name == 'User'" @click="apimRefresh">同步AD域</el-button> -->
        <template v-if="toUpload.indexOf(name) > -1">
          <el-button @click="toLead">{{ translateTitle('Dams.ApplicationInterface.导入') }}</el-button>
          <el-button @click="common_event('export')">{{ translateTitle('Dams.ApplicationInterface.导出') }}</el-button>
        </template>
        <template v-if="name == 'Timer' || name == 'TimerConfig'">
          <el-button @click="batchOpen">
            {{ translateTitle('Dams.ApplicationInterface.批量开启') }}
          </el-button>
          <el-button @click="batchClose">
            {{ translateTitle('Dams.ApplicationInterface.批量关闭') }}
          </el-button>
        </template>
        <template v-if="name == 'MessageConfig'">
          <el-button @click="apimRefresh">{{ translateTitle('Dams.ApplicationInterface.刷新缓存') }}</el-button>
          <el-button @click="batchDelete">
            {{ translateTitle('Dams.ApplicationInterface.一键删除') }}
          </el-button>
          <el-button @click="batchExport">{{ translateTitle('Dams.ApplicationInterface.批量导出') }}</el-button>
          <vui-upload
            ref="fileUploadRefBatch"
            :auto-upload="true"
            file-name="uploadFile"
            :limit="1"
            :post-data="{ method: 'apim.collection.message.config.import', data: '{}' }"
            :show-file-list="false"
            :url="`${configSetting.domain}${configSetting.baseUrl}`"
            @uploadSuccess="uploadSuccessBatch"
          >
            <el-button>{{ translateTitle('Dams.ApplicationInterface.批量导入') }}</el-button>
          </vui-upload>
        </template>
        <slot name="pageItme"></slot>
      </div>
    </div>
    <div style="display: flex">
      <div :style="{ width: drawer ? '50%' : '100%' }">
        <Table
          ref="main_Table"
          :btn-fix="btnFix"
          :column-list="mainTableColumn"
          :get-height="getHeight"
          :loading="tableLoading"
          :name="mainTable.name"
          :style="{ height: `${getHeight}px` }"
          :tables="mainTable"
        />
      </div>
      <div v-show="drawer" class="tab-content" style="width: 50%">
        <el-tabs v-model="tabName" v-loading="tabLoading" type="card" @tab-click="handleClick">
          <el-tab-pane v-for="(item, index) of newTabList" :key="index" :label="item.title" :name="item.name">
            <Table
              v-if="item.name === 'four'"
              :btn-fix="btnFix"
              :column-list="viceTableColumn"
              :get-height="`${getHeight - 100}`"
              :name="name"
              :tables="viceTable"
            />
            <!-- <CodeEditor v-else :ref="'VuiCodeEditor' + index" v-model="vuiCodevalue" :name="name" /> -->
            <p
              v-else-if="item.name === 'first'"
              id="msgCode"
              style="background-color: #1e1e1e; color: #fff; overflow-x: auto"
              :style="{ height: `${getHeight - 130}px` }"
            >
              <!-- {{ vuiCodevalue }} -->
            </p>
            <p v-else style="background-color: #1e1e1e; color: #fff; overflow-x: auto" :style="{ height: `${getHeight - 130}px` }">
              {{ vuiCodevalue }}
            </p>
            <div v-if="item.name === 'second'" style="margin-top: 10px">
              <el-button type="primary" @click="jsonFormatting">{{ translateTitle('Dams.ApplicationInterface.JSON格式化') }}</el-button>
            </div>
          </el-tab-pane>
        </el-tabs>
        <vui-icon class="back" icon="arrow-right-circle-fill" @click="backTab" />
      </div>
    </div>
    <el-dialog v-model="detailsDialog" :title="translateTitle('Dams.ApplicationInterface.Sql详情')" width="80%">
      <el-form v-if="detailsDialog" ref="form" label-position="top" :model="sqlForm">
        <el-form-item :label="translateTitle('Dams.ApplicationInterface.执行SQL')">
          <CodeEditor ref="VuiCodeEditor_SQL" v-model="sqlForm.SQL" :name="name" />
        </el-form-item>
        <el-form-item :label="translateTitle('Dams.ApplicationInterface.SQL参数')">
          <CodeEditor ref="VuiCodeEditor_PARAMS_S" v-model="sqlForm.PARAMS_S" :cm-options="jsonOptions" :name="name" />
        </el-form-item>
        <el-form-item :label="translateTitle('Dams.ApplicationInterface.结果集')">
          <CodeEditor ref="VuiCodeEditor_RESULTS_S" v-model="sqlForm.RESULTS_S" :cm-options="jsonOptions" :name="name" />
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- <el-dialog v-model="addDialog" title="用户" width="80%"> -->
    <el-dialog
      v-model="addDialog"
      :close-on-click-modal="false"
      :title="dialogType == 'add' ? translateTitle('Dams.ApplicationInterface.新增') : translateTitle('Dams.ApplicationInterface.编辑')"
      width="80%"
      @close="close"
    >
      <Forms
        v-if="addDialog"
        ref="formDialogs"
        :data-from="formDialog"
        :list="pageSetting.dialog"
        :name="name"
        :type="dialogType"
        :vui-cron-show="vuiCronShow"
      />
    </el-dialog>
    <el-dialog v-model="updatePasswordDialog" :close-on-click-modal="false" :title="translateTitle('Dams.ApplicationInterface.修改密码')" width="80%">
      <Forms
        v-if="updatePasswordDialog"
        :data-from="updateForm"
        :list="updatePasswordList"
        name="newPassword"
        @newPassword_editor="newPassword_editor"
      />
    </el-dialog>
    <el-dialog v-model="formattingDialog" :title="translateTitle('Dams.ApplicationInterface.JSON格式化数据')" width="80%">
      <CodeEditor v-if="formattingDialog" v-model="formattingData" :cm-options="jsonOptions" :height="true" />
    </el-dialog>
    <Download
      v-if="Object.keys(pageSetting).length > 0 && downloadModal"
      :checkboxlist="checkboxList"
      :download-methods="pageSetting.downloadMethod"
      :is-modal="downloadModal"
      :search-form="subForm"
      :search-table-methods="pageSetting.search.form.method"
      :sub-system="mainTable.subsystem"
      :table-column="mainTableColumn"
      :tablelist="mainTable.tableList"
      @close="downloadClose"
    />
    <Upload
      v-if="uploadModal"
      :export-form="mainTable.exportForm"
      :is-modal="uploadModal"
      :table-column="mainTableColumn"
      :template-method="mainTable.templateMethod"
      :upload-options="mainTable.uploadOptions"
      @closeUpload="closeUpload"
    />
  </div>
</template>

<script>
  import Table from './table.vue'
  import Forms from './forms'
  import Download from './download'
  import Upload from './upload'
  import { GFCD } from '@/utils/utils'
  import { getList, apimRequest, download } from '../api/home'
  import debounce from 'lodash/debounce'
  import CodeEditor from './codeEditor'
  import cloneDeep from 'lodash/cloneDeep'
  import isArray from 'lodash/isArray'
  import { translateTitle } from '@/utils/i18n'
  import list from './constant'
  export default {
    name: 'PublicPage',
    components: { Table, Forms, CodeEditor, Download, Upload },
    props: {
      btnFix: {
        type: Boolean,
        default: false,
      },
      //主table包含list和page，size内容
      tables: {
        type: Object,
        default: () => {},
      },
      //副table包含list和page，size内容
      viceTables: {
        type: Object,
        default: () => {},
      },
      //表格表单的名字（主要用作this.$pub和this.$sub的事件绑定）
      name: {
        type: String,
        default: '',
      },
      //所属子系统
      subSystem: {
        type: String,
        default: 'DAMS',
      },
      //选项卡List
      tabList: {
        type: Array,
        default: () => [],
      },
      //页面配置json参数
      jsonObj: {
        type: Object,
        default: () => {},
      },
      apiParameter: {
        type: Object,
        default: () => {},
      },
    },
    data() {
      return {
        tabLoading: false,
        uploadModal: false,
        downloadModal: false,
        toCopy: [
          'MessageId',
          'WmsRoleList',
          'LwmsRoleList',
          'WcsRoleList',
          'LpmsRoleList',
          'LesRoleList',
          'MessageFiledXml',
          'MessageFiledMapping',
          'StdTable',
          'Timer',
          'MessageConfig',
          'MessageConfigValue',
          'MessageFiledMapping',
          'MessageId',
          'MessageSql',
          'MessageStructure',
          'RuleMessage',
          'SendStdTable',
          'StdRule',
        ],
        noAdd: [
          'WmsUserRole',
          'WmsRoleMenuButton',
          'WmsUserWarehouse',
          'WmsUsercargoOwner',
          'WmsUserReceipts',
          'WcsUserRole',
          'LpmsUserRole',
          'LwmsUserRole',
          'LesUserRole',
          'WcsRoleMenuButton',
          'LpmsRoleMenuButton',
          'LwmsRoleMenuButton',
          'LesRoleMenuButton',
        ],
        toUpload: [
          'CustOrg',
          'MessageConfig',
          'MessageConfigValue',
          'MessageFiledMapping',
          'MessageFiledXml',
          'MessageId',
          'MessageSql',
          'MessageStructure',
          'RuleMessage',
          'SendStdTable',
          'StdRule',
          'StdTable',
          'WmsRoleList',
          'LwmsRoleList',
          'WcsRoleList',
          'LpmsRoleList',
          'LesRoleList',
        ],
        jsonOptions: {
          theme: 'dracula',
          foldGutter: true,
          mode: 'application/json', //设置json模式
          lineNumbers: true, //是否显示左边换行术字
          lineWrapping: true, //是否折叠
          // matchBrackets: true,
          indentUnit: 2,
          // readOnly: true,
          gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
        },
        formattingData: '',
        formattingDialog: false,
        vuiCronShow: true,
        vuiCodevalue: '',
        updatePasswordDialog: false,
        updateForm: {},
        configSetting: {},
        updatePasswordList: {
          form: {
            method: '',
            name: 'dialog',
            field: [
              {
                type: 'input',
                name: 'NEWPASSWORD',
                label: translateTitle('Dams.ApplicationInterface.新密码'),
                labelHidden: false,
                isRules: true,
                showPassword: true,
              },
              {
                type: 'input',
                name: 'CONFIRM_NEWPASSWORD',
                label: translateTitle('Dams.ApplicationInterface.确认新密码'),
                labelHidden: false,
                isRules: true,
                showPassword: true,
              },
              {
                type: 'button',
                label: translateTitle('Dams.ApplicationInterface.提交'),
                labelHidden: true,
              },
            ],
          },
        },
        dialogType: '',
        mainTable: {},
        viceTable: {},
        sqlForm: {},
        tabName: 'first',
        formData: {
          CREATE_TIME: [],
        },
        addDialog: false,
        formDialog: {},
        drawer: false,
        unsubs: [],
        subForm: {},
        msgs: {
          REQUEST_MSG: '',
          RESPONSE_MSG: '',
          EXCEPTION_MSG: '',
        },
        isEditor: false,
        clientHeight: 0,
        REQUEST_UUID: '',
        detailsDialog: false,
        newTabList: [],
        tableTopList: [], //table外面的按钮
        checkboxList: [], //选中行数据
        tableLoading: false,
      }
    },
    computed: {
      getHeight() {
        if (this.name == 'APILog' || this.name == 'TraceLog') {
          return `${this.clientHeight - 220}`
        } else {
          return `${this.clientHeight - 150}`
        }
      },
      pageSetting() {
        return this.jsonObj[this.name] || {}
      },
      columnsData() {
        let arr = this.mainTableColumn.filter((el) => el.label)
        arr.forEach((row) => {
          row.checked = true
        })
        return arr
      },
      mainTableColumn() {
        if (this.pageSetting.dialog) {
          let arr = this.pageSetting.dialog.form.field
          let newArr = []
          arr.forEach((v) => {
            if (v.type != 'button' && v.type != 'line' && !v.tableHidden && v.type != 'userPeriod') {
              newArr.push({
                label: v.label,
                porp: v.name,
                type: v.type,
              })
            }
            if (v.type == 'userPeriod') {
              newArr.push({
                label: v.label,
                porp: v.name.split(',')[0] + ',' + v.name.split(',')[1],
                type: v.type,
              })
            }
          })
          return newArr
        } else {
          return []
        }
      },
      viceTableColumn() {
        if (this.pageSetting.dialog) {
          let arr = this.pageSetting.dialog.form.field1
          let newArr = []
          arr.forEach((v) => {
            if (v.type != 'button' && v.type != 'line') {
              newArr.push({
                label: v.label,
                porp: v.name,
                // tableHidden: v.tableHidden,
                // type: v.type,
              })
            }
          })
          return newArr
        } else {
          return []
        }
      },
    },
    watch: {
      tables: {
        deep: true,
        handler(newval) {
          this.mainTable = newval
        },
      },
      viceTables: {
        deep: true,
        handler(newval) {
          this.viceTable = newval
        },
      },
      tabList: {
        deep: true,
        handler(newval) {
          this.newTabList = newval
        },
      },
    },
    created() {
      this.configSetting = GFCD(this.subSystem.toLocaleLowerCase())
      let menuBtns = this.$store.getters['user/menuBtns']
      menuBtns.forEach((row) => {
        if (this.$route.name.indexOf(row.MENU_CODE) > -1 && row.SHOW_POSTION == 'tableTop') {
          this.tableTopList.push(row)
        }
      })
    },
    mounted() {
      this.init()
      if (this.apiParameter && Object.keys(this.apiParameter).length > 0) {
        for (const key in this.apiParameter) {
          const element = this.apiParameter[key]
          this.formData[key] = element
        }
        this.onSubmit([this.formData])
      }
    },
    unmounted() {
      this.unsubs.forEach((v) => {
        this.$unsub(v)
      })
    },
    methods: {
      resetApl() {
        this.formData = {}
        this.onSubmit([this.formData])
      },
      batchExport() {
        let tableList = this.$refs['main_Table'].$refs[`xTable${this.name}`].getCheckboxRecords()
        if (tableList.length == 0) return this.$baseMessage(translateTitle('Dams.ApplicationInterface.请选择数据'), 'error')
        this.$prompt('请输入文件名', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        })
          .then(({ value }) => {
            let subList = cloneDeep(list)
            subList.splice(0, 1)
            subList.splice(subList.length - 2, 1)
            subList.forEach((row) => {
              row['#EXPORT_WHERE#']['MESSAGE_GROUP_ID'] = tableList.map((el) => el.MESSAGE_GROUP_ID).join(',')
              row['#EXPORT_WHERE#']['MESSAGE_ID'] = tableList.map((el) => el.MESSAGE_ID).join(',')
              row['#EXPORT_FILE_NAME#'] = translateTitle('Dams.ApplicationInterface.导出文件') + '_' + new Date().getTime()
              row['#EXPORT_API_NAME#'] = 'apim.collection.message.config.export'
              if (row['#EXPORT_SHEET_NAME#'] == 'sys_message_config') {
                row['#EXPORT_SQL_ID#'] = 'apim.collection.source.export'
              } else if (row['#EXPORT_SHEET_NAME#'] == 'sys_message_sql') {
                row['#EXPORT_SQL_ID#'] = 'apim.collection.ms.export'
              } else if (row['#EXPORT_SHEET_NAME#'] == 'sys_messageid') {
                row['#EXPORT_SQL_ID#'] = 'apim.collection.mid.export'
              }
            })
            console.log(subList)
            download(`${this.configSetting.domain}${this.configSetting.baseUrl}`, {
              data: JSON.stringify(subList),
              method: 'apim.collection.message.config.export',
            }).then((res) => {
              console.log(res)
              let blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
              let reader = new FileReader()
              reader.readAsDataURL(blob) // 转换为base64，可以直接放入a标签href
              reader.onload = (e) => {
                let a = document.createElement('a')
                a.download = value + '.xlsx'
                a.href = e.target.result
                a.click()
              }
            })
          })
          .catch(() => {
            console.log('取消输入')
          })
      },
      uploadSuccessBatch(file) {
        let res = file.fileList[file.fileList.length - 1].response
        if (res.code == '00000') {
          this.$baseMessage(translateTitle('Dams.ApplicationInterface.导入成功') + `!`, 'success')
        } else {
          this.$baseMessage(res.msg, 'error')
        }
        console.log(this.$refs)
        this.$refs['fileUploadRefBatch'].$refs.upload.clearFiles()
        this.onSubmit([{}])
      },
      async batchDelete() {
        this.$confirm(
          translateTitle('Dams.ApplicationInterface.确定') + translateTitle('Dams.ApplicationInterface.删除所选接口与之相关所有数据'),
          translateTitle('Dams.ApplicationInterface.提示'),
          {
            confirmButtonText: translateTitle('Dams.ApplicationInterface.确定'),
            cancelButtonText: translateTitle('Dams.ApplicationInterface.取消'),
            type: 'warning',
          }
        ).then(async () => {
          let list = this.$refs['main_Table'].$refs[`xTable${this.name}`].getCheckboxRecords()
          if (list.length == 0) return this.$baseMessage(translateTitle('Dams.ApplicationInterface.请选择数据'), 'error')
          let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
          let res = await getList(url, {
            data: JSON.stringify(list),
            method: this.pageSetting.deleteMethod,
          })
          this.$baseMessage(`${res.msg}!`, 'success')
          this.onSubmit(this.subForm)
        })
      },
      batchOpen() {
        this.$confirm(
          translateTitle('Dams.ApplicationInterface.确定') + translateTitle('Dams.ApplicationInterface.批量开启'),
          translateTitle('Dams.ApplicationInterface.提示'),
          {
            confirmButtonText: translateTitle('Dams.ApplicationInterface.确定'),
            cancelButtonText: translateTitle('Dams.ApplicationInterface.取消'),
            type: 'warning',
          }
        ).then(async () => {
          let list = this.$refs['main_Table'].$refs[`xTable${this.name}`].getCheckboxRecords()
          if (list.length == 0) return this.$baseMessage(translateTitle('Dams.ApplicationInterface.请选择数据'), 'error')
          let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
          list.forEach((r) => {
            r.TIMER_IS_ENABLE = 'Y'
          })
          let method = 'dams.timer.edit'
          let res = await getList(url, {
            data: JSON.stringify(list),
            method: method,
          })
          this.$baseMessage(`${res.msg}!`, 'success')
          this.onSubmit(this.subForm)
        })
      },
      batchClose() {
        this.$confirm(
          translateTitle('Dams.ApplicationInterface.确定') + translateTitle('Dams.ApplicationInterface.批量关闭'),
          translateTitle('Dams.ApplicationInterface.提示'),
          {
            confirmButtonText: translateTitle('Dams.ApplicationInterface.确定'),
            cancelButtonText: translateTitle('Dams.ApplicationInterface.取消'),
            type: 'warning',
          }
        ).then(async () => {
          console.log(this.$refs['main_Table'].$refs[`xTable${this.name}`].getCheckboxRecords())
          let list = this.$refs['main_Table'].$refs[`xTable${this.name}`].getCheckboxRecords()
          if (list.length == 0) return this.$baseMessage(translateTitle('Dams.ApplicationInterface.请选择数据'), 'error')
          list.forEach((r) => {
            r.TIMER_IS_ENABLE = 'N'
          })
          let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
          let method = 'dams.timer.edit'
          let res = await getList(url, {
            data: JSON.stringify(list),
            method: method,
          })
          this.$baseMessage(`${res.msg}!`, 'success')
          this.onSubmit(this.subForm)
        })
      },
      translateTitle,
      async appendixDownload() {
        console.log(this.$store.getters['user/getConstant'])
        console.log(this.$refs['main_Table'].$refs.xTableTraceLog.getCheckboxRecords())
        let list = this.$refs['main_Table'].$refs.xTableTraceLog.getCheckboxRecords()
        if (list.length == 0) return this.$baseMessage(translateTitle('Dams.ApplicationInterface.请选择数据'), 'error')
        list.forEach((r) => {
          r.ORG_ID = this.$store.getters['user/getConstant']['#ORG_ID#']
        })
        let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
        let method = 'dams.file.common.download'
        let res = await download(url, {
          data: JSON.stringify(list),
          method: method,
        })
        if (res.size) {
          // 针对下载请求返回失败之后的处理等
          // 将blob转为json
          const reader = new FileReader()
          let parseObj = null
          reader.readAsText(res, 'utf-8')
          reader.onload = () => {
            parseObj = JSON.parse(reader.result)
            console.log(parseObj)
            this.$baseMessage(parseObj.msg, 'error')
          }
        } else {
          let blob = new Blob([res.data])
          console.log(blob)
          let downloadElement = document.createElement('a')
          let href = window.URL.createObjectURL(blob)
          downloadElement.href = href
          downloadElement.download = decodeURI(res.disposition.split("''")[res.disposition.split("''").length - 1])
          document.body.appendChild(downloadElement)
          downloadElement.click()
          document.body.removeChild(downloadElement)
          window.URL.revokeObjectURL(href)
          console.log(module)
        }
      },
      //wms角色复制
      roleCopy() {
        if (this.checkboxList.length == 0)
          return this.$message({ message: translateTitle('Dams.ApplicationInterface.请选择数据后再进行复制'), type: 'error' })
        if (this.checkboxList.length > 1)
          return this.$message({ message: translateTitle('Dams.ApplicationInterface.只能选择一项数据进行复制'), type: 'error' })
        let form = cloneDeep(this.checkboxList[0])
        delete form._X_ID
        delete form.ID
        delete form.ORG_ID
        delete form['#SEQ#']
        let emptyKeyList = ['ROLE_ID', 'ADDTIME', 'ADDWHO', 'EDITTIME', 'EDITWHO']
        let list = []
        if (this.tables.copyFromKey && this.tables.copyFromKey.length > 0) {
          list = emptyKeyList.concat(this.tables.copyFromKey)
        } else {
          list = emptyKeyList
        }
        for (const key in form) {
          list.forEach((row) => {
            if (key == row) form[row] = ''
          })
        }
        this.vuiCronShow = true
        this.addDialog = true
        this.isEditor = false
        this.dialogType = 'add'
        this.formDialog = form
      },
      closeUpload() {
        console.log('closeUpload')
        this.uploadModal = false
        this.formData = {
          CREATE_TIME: [],
        }
        this.mainTable.limit = 1
        this.onSubmit([{}])
      },
      toLead() {
        this.uploadModal = true
      },
      downloadClose(row) {
        this.downloadModal = row
      },
      async apimRefresh() {
        let damsurl = GFCD('apim')
        let url = `${damsurl.domain}/apim/config/redis/reload`
        let res = await apimRequest(url, '', { 'Content-Type': 'application/json' })
        this.$baseMessage(res.msg, 'success')
      },
      validateJSON(data) {
        if (typeof data == 'string') {
          try {
            var obj = JSON.parse(data)
            if (typeof obj == 'object' && obj) {
              return true
            } else {
              return false
            }
          } catch (e) {
            return false
          }
        }
      },
      jsonFormatting() {
        // this.formatting(this.validateJSON)
        if (!this.validateJSON(this.vuiCodevalue)) return this.$baseMessage(translateTitle('Dams.ApplicationInterface.JSON格式错误'), 'error')
        this.formattingData = this.vuiCodevalue
          ? JSON.stringify(JSON.parse(this.vuiCodevalue), null, 4)
          : translateTitle('Dams.ApplicationInterface.暂无数据')
        this.formattingDialog = true
      },
      export() {
        this.downloadModal = true
      },
      uploadSuccess(file) {
        console.log('uploadSuccess')
        let res = file.fileList[file.fileList.length - 1].response
        if (res.code == '00000') {
          this.$baseMessage(translateTitle('Dams.ApplicationInterface.导入成功') + `!`, 'success')
        } else {
          this.$baseMessage(res.msg, 'error')
        }
        this.$refs['fileUploadRef'].$refs.upload.clearFiles()
        this.onSubmit([{}])
      },
      async synchronization() {
        let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
        let res = await getList(url, {
          data: JSON.stringify({}),
          method: 'LDAP',
        })
        if (res.code == '00000') {
          this.$baseMessage(res.msg, 'success')
        }
        console.log(res)
      },
      common_event(event_name) {
        this[event_name]()
      },
      newAdd() {
        this.addDialog = true
        this.isEditor = false
        this.dialogType = 'add'
        let arr = this.pageSetting.dialog.form.field
        this.vuiCronShow = true
        arr.forEach((v) => {
          // if (!v.hidden) {
          // 下拉选
          if (v.type == 'select') {
            this.formDialog[v.name] = ''
            if (v.isFixed) {
              this.formDialog[v.name] = v.options[0].CODE
              return
            }
            if (v.value) {
              this.formDialog[v.name] = v.value
              return
            }
          }
          // input和textarea
          else if (v.type == 'input' || v.type == 'textarea') {
            if (!!v.value != false) {
              // 有默认值渲染
              this.formDialog[v.name] = v.value
            } else {
              // 没有默认值渲染空
              this.formDialog[v.name] = null
            }
          } else if (v.type == 'imgUpload') {
            this.formDialog[v.name] = ''
          } else if (v.type == 'radio') {
            this.formDialog[v.name] = v.value ? v.value : ''
          } else if (v.type == 'dateTime') {
            this.formDialog[v.name] = v.value ? v.value : null
          } else if (v.type == 'switch') {
            this.formDialog[v.name] = v.value ? v.value : null
          } else if (v.type == 'numInput') {
            this.formDialog[v.name] = v.value ? v.value : 0
          } else if (v.type == 'userPeriod') {
            let nameList = v.name.split(',')
            this.formDialog[nameList[0]] = v.value ? v.value : ''
            this.formDialog[nameList[1]] = v.value ? v.value : '天'
          }
          // }
        })
        if (this.name == 'UserList') {
          this.formDialog.TYPE = 'add'
        }
        delete this.formDialog.ID
      },
      // copy() {},
      backTab() {
        this.drawer = false
      },
      windowResize: debounce(function () {
        this.clientHeight = document.documentElement.clientHeight
      }, 100),
      init() {
        // let menuBtns = this.$store.getters['user/menu']
        // console.log(menuBtns.find((el) => el.name == '100').children.find(el=>el.component == 'views/wmsMenu/wmsRoleList').path)
        if (this.tables && JSON.stringify(this.tables) != '{}') this.mainTable = this.tables
        if (this.viceTables && JSON.stringify(this.viceTables) != '{}') this.viceTable = this.viceTables
        if (this.tabList && this.tabList.length > 0) this.newTabList = this.tabList
        if (this.name == 'Timer') this.formData.SUB_SYSTEM = 'APIM'
        if (this.name == 'WmsLog') this.formData.SUB_SYSTEM = 'WMS'
        this.eventInit()
        this.windowResize()
      },
      handleClick() {
        switch (this.tabName) {
          case 'first':
            this.vuiCodevalue = this.newTabList[0].value || translateTitle('Dams.ApplicationInterface.暂无数据')
            break
          case 'second':
            this.vuiCodevalue = this.newTabList[1].value || translateTitle('Dams.ApplicationInterface.暂无数据')
            break
          case 'thrid':
            this.vuiCodevalue = this.newTabList[2].value || translateTitle('Dams.ApplicationInterface.暂无数据')
            break
          default:
            break
        }
      },
      //查询msg日志
      async getMsg(REQUEST_UUID) {
        let obj = { '#LIMIT#': 1, '#PAGE_SIZE#': 9999 }
        if (this.name != 'TimerLog') {
          obj.FLAG = 'Y'
          obj.filename = `${REQUEST_UUID}_MSG`
        } else {
          obj.REQUEST_UUID = REQUEST_UUID
        }
        this.tabLoading = true
        let method = this.pageSetting.msgMethod
        let res = await getList(`${this.configSetting.domain}${this.configSetting.baseUrl}`, {
          data: JSON.stringify(obj),
          method: method,
        })
        this.tabLoading = false
        this.msgs = res.data[method].data[0]
        this.newTabList.forEach((row) => {
          console.log(row)
          if (row.name == 'first') {
            row.value = res.data[method].data[0] ? res.data[method].data[0]?.REQUEST_MSG : ''
          }
          if (row.name == 'second') {
            row.value = res.data[method].data[0] ? res.data[method].data[0]?.RESPONSE_MSG : ''
          }
          if (row.name == 'thrid') {
            console.log(res.data[method].data)
            row.value = ''
            if (res.data[method].data.length > 0) {
              for (let index = 0; index < res.data[method].data.length; index++) {
                const element = res.data[method].data[index]
                row.value = `${row.value}\n${element.EXCEPTION_MSG}`
              }
            } else {
              row.value = res.data[method].data[0]?.EXCEPTION_MSG
            }
          }
        })
        switch (this.tabName) {
          case 'first':
            this.vuiCodevalue = this.newTabList[0].value || translateTitle('Dams.ApplicationInterface.暂无数据')
            break
          case 'second':
            this.vuiCodevalue = this.newTabList[1].value || translateTitle('Dams.ApplicationInterface.暂无数据')
            break
          case 'thrid':
            this.vuiCodevalue = this.newTabList[2].value || translateTitle('Dams.ApplicationInterface.暂无数据')
            break
          default:
            break
        }
        document.getElementById('msgCode').innerHTML = this.newTabList[0].value || translateTitle('Dams.ApplicationInterface.暂无数据')
      },
      //查询sql日志
      async getSql(REQUEST_UUID) {
        let method = this.pageSetting.sqlMethod
        let res = await getList(`${this.configSetting.domain}${this.configSetting.baseUrl}`, {
          data: JSON.stringify({
            filename: REQUEST_UUID + '_SQL',
            '#LIMIT#': this.viceTable.limit,
            '#PAGE_SIZE#': this.viceTable.pageSize,
            FLAG: 'Y',
          }),
          method: method,
        })
        this.viceTable.tableList = res.data[method].data ? res.data[method].data : []
        this.viceTable.tableList.forEach((row) => {
          row.SQLstr = row.SQL[0]
          row.PARAMS_S = isArray(row.PARAMS) ? JSON.stringify(row.PARAMS, null, 4) : JSON.stringify(JSON.parse(row.PARAMS), null, 4)
          row.RESULTS_S =
            typeof row.RESULTS == 'object'
              ? JSON.stringify(row.RESULTS, null, 4)
              : row.RESULTS
              ? JSON.stringify(JSON.parse(row.RESULTS), null, 4)
              : ''
        })
        this.viceTable.count = res.data[method].count
      },
      formatDate(date) {
        date = new Date(date)
        var y = date.getFullYear()
        var m = date.getMonth() + 1
        var d = date.getDate()
        var h = date.getHours()
        var m1 = date.getMinutes()
        var s = date.getSeconds()
        m = m < 10 ? '0' + m : m
        d = d < 10 ? '0' + d : d
        h = h < 10 ? '0' + h : h
        m1 = m1 < 10 ? '0' + m1 : m1
        s = s < 10 ? '0' + s : s
        return y + '-' + m + '-' + d + ' ' + h + ':' + m1 + ':' + s
      },
      close() {
        this.vuiCronShow = false
      },
      async saveDialog(p) {
        let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
        let method = ''
        if (this.isEditor) {
          method = this.pageSetting.updateMethod
        } else {
          method = this.pageSetting.addMethod
        }
        await getList(url, {
          data: JSON.stringify(p),
          method: method,
        })
        this.$baseMessage(translateTitle('Dams.ApplicationInterface.提交成功') + `!`, 'success')
        this.onSubmit(this.subForm)
      },
      //禁用/启用
      isForbidden(p) {
        let hint = ''
        let hint1 = ''
        if (p.ACTIVE_FLAG == 'Y') {
          hint = translateTitle('Dams.ApplicationInterface.确定启用该用户')
          hint1 = translateTitle('Dams.ApplicationInterface.启用成功')
        } else {
          hint = translateTitle('Dams.ApplicationInterface.确定禁用该用户')
          hint1 = translateTitle('Dams.ApplicationInterface.禁用')
        }
        this.$confirm(hint, translateTitle('Dams.ApplicationInterface.提示'), {
          confirmButtonText: translateTitle('Dams.ApplicationInterface.确定'),
          cancelButtonText: translateTitle('Dams.ApplicationInterface.取消'),
          type: 'warning',
        })
          .then(async () => {
            let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
            await getList(url, {
              data: JSON.stringify(p),
              method: this.pageSetting.forbiddenMethod,
            })
            this.$baseMessage(`${hint1}!`, 'success')
            this.onSubmit(this.subForm)
          })
          .catch((e) => {
            console.log(e)
          })
      },
      //重置密码
      pswReset(p) {
        this.$confirm(translateTitle('Dams.ApplicationInterface.确定重置该用户密码'), translateTitle('Dams.ApplicationInterface.提示'), {
          confirmButtonText: translateTitle('Dams.ApplicationInterface.确定'),
          cancelButtonText: translateTitle('Dams.ApplicationInterface.取消'),
          type: 'warning',
        })
          .then(async () => {
            let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
            await getList(url, {
              data: JSON.stringify(p),
              method: this.pageSetting.resetPws,
            })
            this.$baseMessage(translateTitle('Dams.ApplicationInterface.重置成功'), 'success')
            this.onSubmit(this.subForm)
          })
          .catch((e) => {
            console.log(e)
          })
      },
      //搜索
      async onSubmit(p) {
        let sub = JSON.parse(JSON.stringify(p))
        let obj = {}

        if (p.length > 0 && p[0].CREATE_TIME) {
          delete sub[0].CREATE_TIME
          obj = {
            '#LIMIT#': this.mainTable.limit,
            '#PAGE_SIZE#': this.mainTable.pageSize,
            CREATE_TIME_START: p[0].CREATE_TIME[0],
            CREATE_TIME_END: p[0].CREATE_TIME[1],
            ...sub[0],
          }
        } else {
          obj = {
            '#LIMIT#': this.mainTable.limit,
            '#PAGE_SIZE#': this.mainTable.pageSize,

            ...sub[0],
          }
        }
        if (this.mainTable.LANGUAGE_CODE && this.mainTable.SUB_SYSTEM) {
          obj = {
            ...obj,
            LANGUAGE_CODE: this.mainTable.LANGUAGE_CODE,
            // SUB_SYSTEM: this.mainTable.SUB_SYSTEM,
          }
        }
        this.tableLoading = true
        let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
        if (this.pageSetting.search) {
          let res = await getList(url, {
            data: JSON.stringify(obj),
            method: this.pageSetting.search.form.method,
          })
          const type = ['ACTIVE_FLAG', 'BATCH_FLAG', 'UPDATE_FLAG', 'KEY_FLAG', 'IS_TRANSFER_FIELD']
          this.mainTable.tableList = res.data[this.pageSetting.search.form.method].data
          this.mainTable.count = res.data[this.pageSetting.search.form.method].count
          this.mainTable.tableList.forEach((row) => {
            if (row.PASSWORD_PERIOD) {
              row['PASSWORD_PERIOD,PERIOD_UNIT'] = row.PASSWORD_PERIOD + row.PERIOD_UNIT
            }
            for (const key in row) {
              if (type.indexOf(key) > -1) {
                row[key + '_table'] = row[key] === 'N' ? '否' : '是'
              }
            }
            this.setTableRow(row)
          })
          this.tableLoading = false
        }
      },
      setTableRow(row) {
        const conditionKeys = [
          {
            key: 'ADAPTER_TYPE',
            condition: this.name === 'MessageFiledXml' || this.name === 'MessageStructure',
            rowKey: 'ADAPTER_TYPE_table',
          },
          {
            key: 'ALLOW_EMPTY_FLAG',
            condition: this.name === 'MessageFiledXml',
            rowKey: 'ALLOW_EMPTY_FLAG_table',
          },
          {
            key: 'TYPE',
            condition: this.name === 'MessageConfigValue',
            rowKey: 'TYPE_table',
          },
          {
            key: 'DATA_ACTION',
            condition: '',
            rowKey: 'DATA_ACTION_table',
          },
          {
            key: 'IDU_FLAG',
            condition: '',
            rowKey: 'IDU_FLAG_table',
          },
          {
            key: 'OUT_DATA_ACTION',
            condition: '',
            rowKey: 'OUT_DATA_ACTION_table',
          },
        ]
        const list = {
          TYPE: [
            { LABEL: 'ContenType配置', CODE: '1' },
            { LABEL: '文件接口字符集配置', CODE: '2' },
            { LABEL: '密码认证配置', CODE: '10' },
            { LABEL: '验签配置', CODE: '11' },
            { LABEL: 'Token配置', CODE: '16' },
            { LABEL: '简单回写设配置', CODE: '20' },
            { LABEL: 'SP相关参数配置', CODE: '30' },
            { LABEL: '模板回写配置', CODE: '66' },
            { LABEL: '命名空间设配置', CODE: '88' },
            { LABEL: '邮件配置', CODE: '14' },
            { LABEL: 'HttpHeaderParam设置', CODE: '3' },
          ],
          ADAPTER_TYPE: [
            { LABEL: '入向', CODE: 'I' },
            { LABEL: '出向', CODE: 'O' },
            { LABEL: '响应', CODE: 'R' },
          ],
          ALLOW_EMPTY_FLAG: [
            { LABEL: '允许', CODE: 'Y' },
            { LABEL: '不允许', CODE: 'N' },
          ],
          IDU_FLAG: [
            { CODE: 'UPDATE', LABEL: '修改' },
            { CODE: 'D_I', LABEL: '删除再插入' },
            { CODE: 'REJECT', LABEL: '拒绝' },
            { CODE: 'INSERT', LABEL: '插入' },
          ],
          other: [
            { CODE: '01', LABEL: 'XML' },
            { CODE: '10', LABEL: 'JSON' },
            { CODE: '20', LABEL: 'SOAP' },
            { CODE: '40', LABEL: 'DB' },
            { CODE: '42', LABEL: 'DB_MAIL' },
            { CODE: '50', LABEL: 'FTP' },
            { CODE: '51', LABEL: 'TXT' },
            { CODE: '52', LABEL: 'EXCEL' },
            { CODE: '54', LABEL: 'MAIL' },
            { CODE: '55', LABEL: 'FTP_TXT' },
            { CODE: '57', LABEL: 'FTP_CSV' },
            { CODE: '06', LABEL: 'SMS' },
            { CODE: '91', LABEL: 'WECHAT' },
            { CODE: '41', LABEL: '直接调用SP' },
            { CODE: '11', LABEL: 'JSON_XML' },
            { CODE: '30', LABEL: 'LDAP用户拉取' },
            { CODE: '90', LABEL: '标准RFC' },
            { CODE: '99', LABEL: '自定义' },
            { CODE: '53', LABEL: 'CSV' },
            { CODE: '43', LABEL: '查询' },
            { CODE: '21', LABEL: 'SOAP套JSON' },
          ],
        }
        conditionKeys.forEach((r) => {
          const rowList = list[r.key] || list.other
          if (row[r.key] && (r.condition ? r.condition : true)) {
            row[r.rowKey] = rowList.find((el) => el.CODE === row[r.key])?.LABEL || ''
          }
        })
      },
      setFormKey(forms) {
        const joinKeys = ['APPS', 'ORGIDS', 'ORG_CODE', 'APPIDS']
        const deleKeys = ['WAREHOSUENAMELIST', 'BACKGROUND_IMAGE_BASE64url']
        joinKeys.forEach((r) => {
          if (forms[r]) {
            forms[r] = forms[r].join(',')
          }
          if (forms.GROUP_NAME && this.pageSetting.addMethod != 'dams.app.timer.group.insert' && isArray(forms.GROUP_NAME)) {
            console.log('forms.GROUP_NAME', forms.GROUP_NAME)
            forms.GROUP_NAME = forms.GROUP_NAME.join(',')
          }
        })
        deleKeys.forEach((r) => {
          if (forms[r]) {
            delete forms[r]
          }
        })
      },
      // 模态框里面确认之后接口请求函数
      dialogFuc(method) {
        let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
        let subForm = JSON.parse(JSON.stringify(this.formDialog))
        this.setFormKey(subForm)
        if (this.pageSetting.addMethod == 'dams.errcode.add' || this.pageSetting.addMethod == 'dams.errcode.edit') {
          if (subForm.TYPE != subForm.ERROR_CODE[0])
            return this.$baseMessage(translateTitle('Dams.ApplicationInterface.错误代码与所选错误代码类型不符合'), 'error')
        }
        let addMethod = this.pageSetting.addMethod
        if (addMethod == 'dams.userRoleMangage.add') {
          subForm.USER_ID = this.$store.getters['user/uid']
        }
        if (this.name == 'UserList') {
          if (subForm.PASSWORD_SWITCH == 'Y') {
            if (!subForm.PASSWORD_PERIOD || !subForm.PERIOD_UNIT) {
              return this.$baseMessage(translateTitle('Dams.ApplicationInterface.请将周期填写完'), 'error')
            }
            if (isNaN(Number(subForm.PASSWORD_PERIOD))) {
              return this.$baseMessage(translateTitle('Dams.ApplicationInterface.周期应输入数字'), 'error')
            }
            if (subForm.PASSWORD_PERIOD > 30) {
              return this.$baseMessage(`${translateTitle('Dams.ApplicationInterface.周期不能大于30') + subForm.PERIOD_UNIT}`, 'error')
            }
          }
        }
        getList(url, {
          method: method,
          data: JSON.stringify(subForm),
        }).then((res) => {
          if (res.code == '00000') {
            this.$baseMessage(res.msg, 'success')
            if (this.formDialog.ORGIDS) {
              this.formDialog = { ORGIDS: [] }
            } else {
              this.formDialog = {}
            }
            this.addDialog = false
            this.onSubmit(this.subForm)
          }
        })
      },
      async handTrigger(obj) {
        let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
        let res = await getList(url, {
          data: JSON.stringify(obj),
          method: 'dams.timer.trigger',
        })
        this.$baseMessage(res.msg, 'success')
      },
      // 刷新token
      refresh() {
        let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
        let method = ''
        if (this.name == 'UsingJavaToRealizeMaintenance') {
          method = 'defaultRefreshEnvToRedisService.doRefreshBeanConfig'
        } else {
          method = 'defaultRefreshEnvToRedisService.doRefreshProperty'
        }
        getList(url, {
          method: method,
          data: JSON.stringify({}),
        }).then((res) => {
          this.$baseMessage(res.msg, 'success')
        })
      },
      async newPassword_editor() {
        let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
        if (this.updateForm.NEWPASSWORD !== this.updateForm.CONFIRM_NEWPASSWORD)
          return this.$baseMessage(translateTitle('Dams.ApplicationInterface.密码不一致'), 'error')
        await getList(url, {
          data: JSON.stringify(this.updateForm),
          method: this.pageSetting.updatePasswordMethod,
        })
        this.$baseMessage(translateTitle('Dams.ApplicationInterface.修改成功'), 'success')
        this.updateForm = {}
        this.updatePasswordDialog = false
        this.onSubmit(this.subForm)
      },
      eventInit() {
        this.$sub(`${this.name}_Table_clearLockBtn_clearLock`, async (data_arr) => {
          console.log(data_arr)
          let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
          await getList(url, {
            data: JSON.stringify({ USER_ID: data_arr[0].USER_ID }),
            method: 'sysUserServiceImpl.clearLock',
          })
          this.$message({
            type: 'success',
            message: translateTitle('Dams.ApplicationInterface.清除成功'),
          })
        })
        this.unsubs.push(`${this.name}_Table_clearLockBtn_clearLock`)
        //定时器手动触发
        this.$sub(`${this.name}_Table_triggerBtn_${this.name}`, (data_arr) => {
          this.handTrigger(data_arr[0])
        })
        this.unsubs.push(`${this.name}_Table_triggerBtn_${this.tables.name}`)
        //选中行
        this.$sub(`${this.name}_Table_checkbox_${this.mainTable.name}`, (data_arr) => {
          this.checkboxList = data_arr[0]
        })
        this.unsubs.push(`${this.name}_Table_checkbox_${this.tables.name}`)
        //修改密码
        this.$sub(`${this.name}_Table_uploadPasswordBtn_uploadPassword`, async (data_arr) => {
          console.log(data_arr)
          this.updatePasswordDialog = true
          this.updateForm.USER_ID = data_arr[0].USER_ID
        })
        this.unsubs.push(`${this.name}_Table_uploadPasswordBtn_uploadPassword`)
        //打开编辑
        console.log('sub============', `${this.name}_Table_editBtn_${this.tables.name}`)
        this.$sub(`${this.name}_Table_editBtn_${this.tables.name}`, (data_arr) => {
          this.pageSetting.dialog.form.field.forEach((row) => {
            if (row.name) {
              this.formDialog[row.name] = data_arr[0][row.name]
            }
            if (
              (row.name == 'APPS' ||
                row.name == 'ORGIDS' ||
                row.name == 'APPIDS' ||
                (row.name == 'GROUP_NAME' && this.pageSetting.addMethod != 'dams.app.timer.group.insert')) &&
              !data_arr[0][row.name]
            ) {
              this.formDialog[row.name] = []
            }
            if (row.name == 'APP_NAME') {
              this.formDialog[row.name] = data_arr[0]['APP_NAME_CODE']
              row.options = [{ CODE_ID: data_arr[0]['APP_NAME_CODE'], NAME: data_arr[0]['APP_NAME'] }]
            }
            if (row.name == 'BUTTON_NAME') {
              this.formDialog[row.name] = data_arr[0]['BUTTON_NAME_CODE']
              row.options = [{ CODE_ID: data_arr[0]['BUTTON_NAME_CODE'], NAME: data_arr[0]['BUTTON_NAME'] }]
            }
          })
          if (this.formDialog.ORGIDS && typeof this.formDialog.ORGIDS == 'string') this.formDialog.ORGIDS = this.formDialog.ORGIDS.split(',')
          if (this.formDialog.APPS && typeof this.formDialog.APPS == 'string') this.formDialog.APPS = this.formDialog.APPS.split(',')
          if (this.formDialog.WAREHOUSELIST) {
            this.formDialog.ORG_CODE = this.formDialog.WAREHOUSELIST.split(',')
          }
          if (this.formDialog.APPIDS && typeof this.formDialog.APPIDS == 'string') this.formDialog.APPIDS = this.formDialog.APPIDS.split(',')
          if (
            this.formDialog.GROUP_NAME &&
            typeof this.formDialog.GROUP_NAME == 'string' &&
            this.pageSetting.addMethod != 'dams.app.timer.group.insert'
          ) {
            this.formDialog.GROUP_NAME = this.formDialog.GROUP_NAME.split(',')
          }
          this.vuiCronShow = true
          if (this.pageSetting.addMethod != 'wmsRoleServiceImpl.save') this.formDialog.ID = data_arr[0].ID
          console.log(this.formDialog)
          this.addDialog = true
          this.isEditor = true
          this.dialogType = 'modify'
          if (this.name == 'UserList') {
            this.formDialog.TYPE = 'update'
          }
        })
        this.unsubs.push(`${this.name}_Table_editBtn_${this.tables.name}`)
        //删除
        this.$sub(`${this.name}_Table_delBtn_${this.tables.name}`, (data_arr) => {
          // 不要触发这个组件里面的确认删除弹框
          if (this.tables.noDelModeify) {
            return
          }
          this.$confirm(translateTitle('Dams.ApplicationInterface.确定删除'), translateTitle('Dams.ApplicationInterface.提示'), {
            confirmButtonText: translateTitle('Dams.ApplicationInterface.确定'),
            cancelButtonText: translateTitle('Dams.ApplicationInterface.取消'),
            type: 'warning',
          })
            .then(async () => {
              let url = `${this.configSetting.domain}${this.configSetting.baseUrl}`
              let method = this.pageSetting.deleteMethod
              let subObj = {}
              let methodList = ['wms.role.deleteById', 'lwms.role.deleteById', 'lpms.role.deleteById', 'wcs.role.deleteById', 'les.role.deleteById']
              if (this.tables.deleteKey && typeof this.tables.deleteKey == 'string') {
                subObj = { [this.tables.deleteKey]: data_arr[0][this.tables.deleteKey] }
                // if (this.tables.deleteKey == 'MESSAGE_GROUP_ID') {
                //   subObj = { [this.tables.deleteKey]: data_arr[0][this.tables.deleteKey], MESSAGE_ID: data_arr[0].MESSAGE_ID }
                // }
              } else if (this.tables.deleteKey && Array.isArray(this.tables.deleteKey)) {
                this.tables.deleteKey.forEach((row) => {
                  subObj[row] = data_arr[0][row]
                })
              } else {
                if (method == 'dams.userRoleMangage.del') {
                  subObj = { USER_ID: data_arr[0].ID, USER_ROLE_ID: data_arr[0].USER_ROLE_ID }
                } else if (methodList.indexOf(method) > -1) {
                  subObj = { ROLE_ID: data_arr[0].ROLE_ID, ACTION: 'DELETE', LANGUAGE: 'zh_CN', OUT_RETURN_CODE: '' }
                } else {
                  subObj = { ...data_arr[0] }
                }
              }
              if (methodList.indexOf(method) > -1) {
                let menu = this.$store.getters['user/menu']
                subObj.MODULE_ID = menu.find((el) => el.name == '100').children.find((el) => el.component == 'views/wmsMenu/wmsRoleList').path
              }
              await getList(url, {
                data: JSON.stringify(subObj),
                method: this.pageSetting.deleteMethod,
              })
              this.$message({
                type: 'success',
                message: translateTitle('Dams.ApplicationInterface.删除成功'),
              })
              this.onSubmit(this.subForm)
            })
            .catch((e) => {
              console.log(e)
            })
        })
        this.unsubs.push(`${this.name}_Table_delBtn_${this.tables.name}`)
        this.$sub(`${this.tables.name}_Table_singleClick_${this.tables.name}`, (data_arr) => {
          this.$pub(`${this.name}_myselfOperation`, data_arr[0])
        })
        this.unsubs.push(`${this.tables.name}_Table_singleClick_${this.tables.name}`)
        //重置
        this.$sub(`${this.name}_forms_reset_search`, (data_arr) => {
          this.formData = {
            CREATE_TIME: [],
          }
          this.mainTable.limit = 1
          this.onSubmit(data_arr)
        })
        this.unsubs.push(`${this.name}_forms_reset_search`)
        //搜索事件
        this.$sub(`${this.name}_forms_on_search`, (data_arr) => {
          this.subForm = data_arr
          this.mainTable.limit = 1
          this.onSubmit(data_arr)
        })
        this.unsubs.push(`${this.name}_forms_on_search`)
        //主table翻页事件
        this.$sub(`${this.name}_Table_on_${this.tables.name}`, (page_arr) => {
          this.mainTable.limit = page_arr[0].limit
          this.mainTable.pageSize = page_arr[0].pageSize
          this.onSubmit(this.subForm)
        })
        this.unsubs.push(`${this.name}_Table_on_${this.tables.name}`)
        //主table双击事件
        this.$sub(`${this.name}_Table_clickOne_${this.tables.name}`, (page_arr) => {
          if (this.name == 'Timer' || this.name == 'TimerConfig' || this.name == 'WmsRoleList') {
            this.pageSetting.dialog.form.field.forEach((row) => {
              if (row.name) {
                this.formDialog[row.name] = page_arr[0][row.name]
              }
              if (
                (row.name == 'APPS' ||
                  row.name == 'ORGIDS' ||
                  row.name == 'APPIDS' ||
                  (row.name == 'GROUP_NAME' && this.pageSetting.addMethod != 'dams.app.timer.group.insert')) &&
                !page_arr[0][row.name]
              ) {
                this.formDialog[row.name] = []
              }
            })
            this.vuiCronShow = true
            this.formDialog.ID = page_arr[0].ID
            this.addDialog = true
            this.isEditor = true
            this.dialogType = 'modify'
          }
          console.log(this.mainTable)
          if (this.mainTable.myselfOperation) {
            // 自己双击事件
            this.$pub(`${this.name}_myselfOperation`, page_arr[0].ID)
          } else {
            if (!this.mainTable.operation) return
            this.drawer = true
            if (this.pageSetting.msgMethod) this.getMsg(page_arr[0].REQUEST_UUID)
            if (this.pageSetting.sqlMethod) this.getSql(page_arr[0].REQUEST_UUID)
            this.REQUEST_UUID = page_arr[0].REQUEST_UUID
          }
        })
        this.unsubs.push(`${this.name}_Table_clickOne_${this.tables.name}`)
        if (this.viceTables && JSON.stringify(this.viceTables) != '{}') {
          //副table翻页事件
          this.$sub(`${this.name}_Table_on_${this.viceTable.name}`, (page_arr) => {
            this.viceTable.limit = page_arr[0].limit
            this.viceTable.pageSize = page_arr[0].pageSize
            this.onSubmit(this.REQUEST_UUID)
          })
          this.unsubs.push(`${this.name}_Table_on_${this.viceTable.name}`)
          //副table双击事件
          this.$sub(`${this.name}_Table_clickOne_${this.viceTable.name}`, (data_arr) => {
            this.detailsDialog = true
            this.sqlForm = data_arr[0]
          })
          this.unsubs.push(`${this.name}_Table_clickOne_${this.viceTable.name}`)
        }
        this.$sub(`${this.mainTable.name}_Table_otherBtn_startUsing`, (data_arr) => {
          let obj = { USER_ID: data_arr[0].USER_ID, ACTIVE_FLAG: '' }
          if (data_arr[0].ACTIVE_FLAG == 'Y') {
            obj.ACTIVE_FLAG = 'N'
          } else {
            obj.ACTIVE_FLAG = 'Y'
          }
          this.isForbidden(obj)
        })
        this.unsubs.push(`${this.mainTable.name}_Table_otherBtn_startUsing`)
        this.$sub(`${this.mainTable.name}_Table_otherBtn_pswAmend`, (data_arr) => {
          console.log(data_arr)
          this.updatePasswordDialog = true
        })
        this.unsubs.push(`${this.mainTable.name}_Table_otherBtn_pswAmend`)
        this.$sub(`${this.mainTable.name}_Table_otherBtn_pswReset`, (data_arr) => {
          let obj = { USER_ID: data_arr[0].USER_ID }
          this.pswReset(obj)
        })
        this.unsubs.push(`${this.mainTable.name}_Table_otherBtn_pswReset`)
        // 模态框里面的确定按钮
        this.$sub(`${this.name}_forms_on_dialog`, (data_arr) => {
          if (data_arr[0] == '提交') {
            // 新增模态框
            if (this.dialogType == 'add') {
              this.dialogFuc(this.pageSetting.addMethod)
            } else if (this.dialogType == 'modify') {
              // 修改模态框
              this.dialogFuc(this.pageSetting.updateMethod)
            }
          }
        })
        this.unsubs.push(`${this.name}_forms_on_dialog`)
      },
    },
  }
</script>

<style lang="scss" scoped>
  @import '@/ve/styles/elements.scss';
  .public-page {
    padding: 15px;
    box-sizing: border-box;
    // display: flex;
    width: 100%;
    .bg-purple {
      padding: 0 10px;
      word-wrap: break-word;
      word-break: break-all;
    }
    .tab-content {
      position: relative;
      .back {
        position: absolute;
        right: 0;
        top: -18px;
        cursor: pointer;
      }
      :deep() {
        .el-tabs__nav-prev,
        .el-tabs__nav-next {
          line-height: 20px;
        }
      }
    }
    :deep() {
      .el-dialog__body {
        .el-form--inline .el-form-item {
          width: 23%;
          display: inline-block;
          // margin-bottom: 0;
        }
        .el-form-item__label {
          display: block;
          text-align: left;
          line-height: 24px;
          font-size: 12px;
        }
        .el-form-item__content {
          width: 100%;
        }
        // .el-select {
        //   width: 100%;
        // }
        .item_button {
          display: block !important;
          width: 100% !important;
          text-align: center;
        }
      }
    }
  }
</style>
